<?php
/**
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file license.txt or that can be found at 
 * http://code.google.com/p/billboardce/wiki/License.
 *
 * @package    Url_Module
 * @category   Model
 * @license    http://code.google.com/p/billboardce/wiki/License New BSD License
 * @version    SVN: $Id: $
 */
class Url_Module implements Plugin_Slide_Type_Interface
{
    public function getTitle()
    {
        return 'Standard URL';
    }
    
    public function getTypeForm()
    {
        $url = new Url_Data();        
        return $url->form()->__toString();
    }
    
    public function saveTypeForm($slideId, array $data)
    {
        $url = new Url_Data();
        
        $form = $url->form(array('slideId' => $slideId));
        
        if ($form->isValid($data)) {
            $existingData = $url->find($slideId);

            $data['slideId'] = $slideId;
            
            if (is_null($existingData)) {
                $url->insert($data);
            } else {
                $url->update($data, null);
            }
        }
        
        return $form->getErrorMessages();
    }
        
    public function getData($slideId)
    {
        $url = new Url_Data();
        
        $data = $url->find($slideId);
        if (is_null($data)) {
            return array();
        } else {
            return $data->toArray();
        }
    }
    
    public function getUrl($slideId)
    {
       $thisSlide = $this->getData($slideId);
       
       return (isset($thisSlide['url'])) ? $thisSlide['url'] : null;
    }
    
    public function buildSlide($view, $slideId)
    {
        // do nothing since we should not need to build a slide
    }
}